package tests.xml;

import java.security.AccessController;
import java.util.Calendar;
import java.util.Date;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import common.utils.StringHelper;

import sun.security.action.GetPropertyAction;

public class TestXml {

	public static void main(String [] args){
		String filename1 = "E:\\java\\myPlugins\\myplugins_for_eclipse3.3" +
				"\\CodeProStudio_v5.3.0_for_Eclipse3.3\\file.exe";
		String filename2 = "E:\\a.txt";
		int idx1 = filename1.lastIndexOf('\\');
		int idx2 = filename2.lastIndexOf('\\');
		File file1 = new File(filename1);
		File file2 = new File(filename2);

		System.out.println(idx2 + "\t" +
				filename2.substring(idx2 + 1) + "\n" +
				filename2.substring(0, idx2));
		System.out.println(file2.getParent() + '\t' + file2.getName());
		System.out.println(idx1 + "\t" +
				filename1.substring(idx1 + 1) + "\n" + 
				filename1.substring(0, idx1));
		System.out.println(file1.getParent() + '\t' + file1.getName());
		System.out.println(((String) AccessController.doPrivileged(
	              new GetPropertyAction("file.separator"))).charAt(0));
		
		int idx = filename2.lastIndexOf("."); 
		String xmlfilename = filename2.substring(0, idx) + ".xml";
		System.out.println(xmlfilename);
		

		File writefile = new File(xmlfilename);
		try{
			if(writefile.exists() == false){
				writefile.createNewFile();
				writefile = new File(xmlfilename);
			}
			FileWriter filewriter = new FileWriter(writefile, true);
			//BufferedWriter bufwriter = new BufferedWriter(filewriter);
			filewriter.write("<?xml version=\"1.0\"?>\n");
			filewriter.flush();
		}catch(Exception d) {
			
		}
		System.out.println(file1.getParent() + "\n" + 
				file1.getPath() + "\n" + 
				file1.getParentFile());
		System.out.println(new Date().toString() + "\n" + Calendar.getInstance().getTime());
		
		
		System.out.println("FT_Abc".substring(2));
		System.out.println(StringHelper.countStr("ABCCAEEDCDCC", ""));
		System.out.println(StringHelper.countStr("ABCCAEEDCDCC", "CC"));
		
	}
}
